<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            background-color: #ccc;
        }

        span {
            font-size: 40px;
            cursor: pointer;
            /* color: rebeccapurple; */
        }
    </style>
</head>

<body>
    <div>
        <span>★</span>
        <span>★</span>
        <span>★</span>
        <span>★</span>
        <span>★</span>
    </div>
</body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
    $(function () {
        let index = 0;
        $('span').mouseover(function () {
            $(this).parent().children().css('color', '');
            $(this).css('color', 'yellow').prevAll().css('color', 'yellow')
        }).mouseleave(function () {
            $(this).parent().children().css('color', '')
            $('span:eq(' + index + ')').css('color', 'yellow').prevAll().css('color', 'yellow')
        }).click(function () {
            $(this).parent().children().css('color', '');
            $(this).css('color', 'yellow').prevAll().css('color', 'yellow')
            index = $(this).index();
        })
    })
</script>

</html>